#Promene
BUILDDIR = build
VPATH = src
BIN = xxshell

#C
CC = gcc

#C++
CPP = g++
CPPSRC = xxShell.cpp Inter.cpp Interpret.cpp Job.cpp JobControl.cpp SingleCommand.cpp ParseException.cpp
CPPOBJ = $(patsubst %.cpp, $(BUILDDIR)/%.o, $(CPPSRC)) $(FOBJ)
CPPLIBS = -lreadline

#YACC
YACC = yacc
YSRC = src/SyntaxAnalyzer.y
YOUTH = build/y.tab.h
YOUTC = build/y.tab.c
YOBJ = build/y.tab.o

#FLEX
FLEX = flex
FSRC = src/LexicalAnalyzer.l
FOUTC = build/lex.yy.c
FOBJ = build/lex.yy.o




build: dirs $(CPPOBJ)
	cp src/Analyzer.h src/SingleCommand.h src/ParseException.h src/printouts.h build/
	$(CPP) $(CPPOBJ) build/y.tab.c -o $(BIN) $(CPPLIBS)
	rm build/Analyzer.h build/SingleCommand.h build/ParseException.h build/printouts.h

$(FOBJ): flex
	$(CC) -c $(FOUTC) -o $(FOBJ)

build/%.o: src/%.cpp $(HEAD)
	$(CPP) -c $< -o $@

flex: yacc
	$(FLEX) -o $(FOUTC) $(FSRC)

yacc: 
	$(YACC) -d $(YSRC) -o $(YOUTC)

dirs:
	mkdir -p $(BUILDDIR)

clean:
	rm -r -f $(BUILDDIR)
	rm -f $(BIN)
